function LoadMetadata() {
    RequestLibraryData("documents?q=id:" + ParentParam("id"), ProcessMetadata);
}

function FindResourceStorage(metadata) {
    for (i in metadata.labels) {
	if (metadata.labels[i][0].substr(0, 8) == "storage:") {
	    return metadata.labels[i][0];
	}
    }
    return null;
}

function ProcessMetadata(results, terms) {
    var metadata = results[0];
    var storage = FindResourceStorage(metadata);
    var url = "";
    if (storage == "storage:site-external") {
	url = metadata.url;
    } else if (storage == "storage:site-youtube") {
	key = metadata.url.substr(metadata.url.indexOf('v=') + 2);
	url = 'http://www.youtube.com/embed/' + key;
    } else if (storage == "storage:google-storage") {
	url = 'http://docs.google.com/viewer?embedded=true&url=' +
	    metadata.url;
    } else {
	url = metadata.url;
    }
    document.getElementById("document_frame").innerHTML =
	'<iframe src="' + url + '" width="100%" height="100%"></iframe>';
}
